import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { RolePermission } from './RolePermission';
import { UserRole } from './UserRole';

@Entity('role', { schema: 'blog_back' })
export class Role {
  @PrimaryGeneratedColumn({
    type: 'int',
    name: 'id',
    comment: '主键id',
    unsigned: true,
  })
  id: number;

  @Column('enum', {
    name: 'isSuper',
    comment: '是否为超级管理员',
    enum: ['1', '0'],
    default: () => "'0'",
  })
  isSuper: '1' | '0';

  @Column('varchar', { name: 'name', comment: '角色名称', length: 32 })
  name: string;

  @Column('varchar', { name: 'zn_name', comment: '角色中文名称', length: 64 })
  znName: string;

  @Column('timestamp', {
    name: 'create_time',
    comment: '创建时间',
    default: () => 'CURRENT_TIMESTAMP',
  })
  createTime: Date;

  @Column('timestamp', {
    name: 'update_time',
    comment: '更新时间',
    default: () => 'CURRENT_TIMESTAMP',
  })
  updateTime: Date;

  @OneToMany(() => RolePermission, (rolePermission) => rolePermission.role)
  rolePermissions: RolePermission[];

  @OneToMany(() => UserRole, (userRole) => userRole.role)
  userRoles: UserRole[];
}
